//
//  MaintenanceServiceSuccessViewController.swift
//  koolcar
//
//  Created by xiantian on 2023/10/30.
//

import UIKit

class MSServiceSuccessViewController: BaseViewController {
    
    private var logoImgView: UIImageView = {
        let tempImgView = UIImageView()
        tempImgView.image = UIImage.init(named: "service_success")
        tempImgView.contentMode = .scaleAspectFit
        return tempImgView
    }()
    
    private var tipLab: UILabel = {
        let tempLab = UILabel()
        tempLab.textColor = Theme.titleLabColor
        tempLab.backgroundColor = UIColor.clear
        tempLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        tempLab.numberOfLines = 1
        tempLab.lineBreakMode = .byTruncatingTail
        tempLab.textAlignment = .center
        tempLab.text = MMLocalizedString("reservation_success", comment: "预约成功")
        return tempLab
    }()
    
    var leftBtn: UIButton = {
        let tempBtn = UIButton()
        tempBtn.layer.borderWidth = 1
        tempBtn.layer.borderColor = Theme.titleLabColor.cgColor
        tempBtn.setup_titleColor(color: Theme.titleLabColor)
        tempBtn.setup_titleLabel(text: MMLocalizedString("return_home", comment: "返回首页"))
        tempBtn.titleLabel?.font = UIFont.init(name: Theme.PingFangSCRegular, size: 16)
        tempBtn.layer.cornerRadius = 8
        tempBtn.layer.masksToBounds = true
        tempBtn.backgroundColor = .white
        return tempBtn
    }()
    
    var rightBtn: UIButton = {
        let tempBtn = UIButton()
        tempBtn.setup_titleColor(color: Theme.whiteColor)
        tempBtn.setup_titleLabel(text: MMLocalizedString("mainten_check_book", comment: "查看预约"))
        tempBtn.titleLabel?.font = UIFont.init(name: Theme.PingFangSCRegular, size: 16)
        tempBtn.layer.cornerRadius = 8
        tempBtn.layer.masksToBounds = true
        tempBtn.setBackgroundImage(UIImage.init(color: Theme.mainColor), for: .normal)
        tempBtn.setBackgroundImage(UIImage.init(color: Theme.mainColorHighLightColor), for: .highlighted)
        return tempBtn
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navBar.title = MMLocalizedString("reservation_server", comment: "预约服务")
        self.navBar.wr_setBottomLineHidden(hidden: true)
        self.view.addSubview(logoImgView)
        self.view.addSubview(tipLab)
        self.view.addSubview(leftBtn)
        self.view.addSubview(rightBtn)
        
        leftBtn.addTarget(self, action: #selector(leftBtnAction), for: .touchUpInside)
        rightBtn.addTarget(self, action: #selector(rightBtnAction), for: .touchUpInside)

        self.addSnpLayout()
    }
    
    private func addSnpLayout(){
        logoImgView.snp.makeConstraints { make in
            make.width.equalTo(100)
            make.height.equalTo(100)
            make.centerX.equalTo(kScreenWidth/2)
            make.top.equalTo(NavBarHight + 100)
        }
        
        tipLab.snp.makeConstraints { make in
            make.top.equalTo(logoImgView.snp.bottom).offset(20)
            make.height.greaterThanOrEqualTo(20)
            make.centerX.equalTo(kScreenWidth/2)
        }
        
        leftBtn.snp.makeConstraints { make in
            make.top.equalTo(tipLab.snp.bottom).offset(40)
            make.left.equalTo(24)
            make.height.equalTo(46)
        }
        
        rightBtn.snp.makeConstraints { make in
            make.top.equalTo(leftBtn.snp.top)
            make.left.equalTo(leftBtn.snp.right).offset(30)
            make.right.equalTo(-24)
            make.height.equalTo(46)
            make.width.equalTo(leftBtn.snp.width)
        }
    }
    
    ///回首页
    @objc func leftBtnAction(){
        self.navigationController?.popToRootViewController(animated: false)
        if let tabbarVC = UIApplication.shared.keyWindow?.rootViewController as? BaseTabbarController {
            tabbarVC.selectedIndex = 0
        }
    }
    
    ///查看预约
    @objc func rightBtnAction(){
        let vc = MyReservationViewController()
        self.navigationController?.pushViewController(vc, animated: true)
    }
}
